package com.startup.yellocar.dao;
import org.hibernate.SessionFactory;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.startup.yellocar.dto.PreferenceDTO;
@Repository
@Transactional
public class PreferenceDAO {
@Autowired
protected SessionFactory sessionFactory;
@Transactional
public void insert(PreferenceDTO preferenceDTO){
sessionFactory.getCurrentSession().save(preferenceDTO);
}
@Transactional
public void update(PreferenceDTO preferenceDTO){
sessionFactory.getCurrentSession().update(preferenceDTO);
}
@Transactional
public PreferenceDTO get(int id) {return (PreferenceDTO) sessionFactory.getCurrentSession().get(PreferenceDTO.class,id);
}
@SuppressWarnings("unchecked")
@Transactional
public List<PreferenceDTO> getAll() {return (List<PreferenceDTO>) sessionFactory.getCurrentSession().createQuery("Select t from PreferenceDTO t").list();
}
@Transactional
public void delete(PreferenceDTO preferenceDTO){
sessionFactory.getCurrentSession().delete(preferenceDTO);
}
}
